﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EntityFrameWorkTest.Models;
using System.Collections.ObjectModel;

namespace EntityFrameWorkTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            textBox1.Text = "";


            using (var db = new DiverContext())
            {

                Diver newDiver = new Diver
                {
                    id = CreateHash(),
                    name = "Knut"
                };
                db.Divers.Add(newDiver);
                db.SaveChanges();

               
                
                var selectQuery = from b in db.Divers
                                orderby b.id
                                select b;
                textBox1.Text += "All persons" + Environment.NewLine;
                foreach (var person in selectQuery)
                {
                    textBox1.Text += person.id + ", " + person.name + Environment.NewLine;
                }

            }



            

        }

        private static int CreateHash()
        {
            int HashCode = DateTime.Now.ToLongTimeString().GetHashCode() % 3000;
            if (HashCode < 0)
                HashCode = -HashCode;
            return HashCode;
        }

    }
}
